package com.hectopascal.enums;

import com.alibaba.fastjson.annotation.JSONType;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.databind.deser.std.EnumDeserializer;

@JSONType(deserializer = EnumDeserializer.class)
public enum UserRoleTypeEnum {
    //管理员
    ADMIN(0, "admin"),
    //员工
    EMPLOYEE(1, "employee");

    UserRoleTypeEnum(int type, String name) {
        this.type = type;
        this.name = name;
    }

    @EnumValue
    private final int type;

    private final String name;

    // 根据 type 获取枚举
    public static String fromType(int type) {
        for (UserRoleTypeEnum role : values()) {
            if (role.getType() == type) {
                return role.getName();
            }
        }
        throw new IllegalArgumentException("Invalid role type: " + type);
    }

    public static int toType(String name) {
        for (UserRoleTypeEnum role : values()) {
            if (role.getName().equals(name)) {
                return role.getType();
            }
        }
        throw new IllegalArgumentException("Invalid role name: " + name);
    }


    public int getType() {
        return type;
    }

    public String getName() {
        return name;
    }

}
